package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService {

    @Autowired
    private StrategyCatalogMapper strategyCatalogMapper;

    @Override
    public void update(StrategyCatalog strategyCatalog) {
        strategyCatalogMapper.updateByPrimaryKey(strategyCatalog);
    }

    @Override
    public void save(StrategyCatalog strategyCatalog) {
        if(strategyCatalog.getSequence()==null){
            int s=strategyCatalogMapper.selectMaxSequence();
            strategyCatalog.setSequence(s+1);
        }
        strategyCatalogMapper.insert(strategyCatalog);
    }

    @Override
    public Travel get(Long id) {
        return null;
    }

    @Override
    public void listAll() {

    }

    @Override
    public PageInfo<StrategyCatalog> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<StrategyCatalog> list=strategyCatalogMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    /**
     * 查询某个攻略的分类
     * @param id
     * @return
     */
    @Override
    public List getByStrategyId(Long id) {
        return strategyCatalogMapper.selectByStrategyId(id);
    }

    /**
     *查询某个攻略分类及文章
     * @param id
     * @return
     */
    @Override
    public List<StrategyCatalog> listByStrategyId(Long id) {
        return strategyCatalogMapper.selectByStrategyId(id);
    }
}
